#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Copyright © 启明星辰 版权所有
# @Time    : 2024/5/28 14:54
# @Author  : 胡浩浩
# @File    : start_server.py
# @IDE     : PyCharm
# @description :
import uvicorn
from fastapi import FastAPI, Request
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.responses import HTMLResponse


class XFrameOptionsMiddleware(BaseHTTPMiddleware):
    async def dispatch(self, request: Request, call_next):
        response = await call_next(request)
        response.headers["X-Frame-Options"] = "ALLOW-FROM http*"
        return response


app = FastAPI()
# 添加中间件
app.add_middleware(XFrameOptionsMiddleware)


@app.get("/")
async def get_index():
    with open("show.html", "r", encoding="utf-8") as file:
        html_content = file.read()
    return HTMLResponse(content=html_content, status_code=200)


if __name__ == '__main__':
    uvicorn.run(app, port=7777, host="192.168.114.124")
